#include "GraphWidgetHistogram.h"

#include <QGLWidget>

GraphWidgetHistogram::GraphWidgetHistogram() :
    GraphWidgetObject()
{
}

GraphWidgetHistogram::GraphWidgetHistogram(const GraphWidgetHistogram& gwl) :
    GraphWidgetObject(gwl)
{

}

GraphWidgetHistogram::GraphWidgetHistogram(QVector<int> histogramValues, bool graphInYDirection,
                                           double start, double interval, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    double j = start;
    for (int i = 0; i < histogramValues.count(); i++, j+=interval) {
        QPointF point;
        if (graphInYDirection) {
            point.setX(j);
            point.setY(histogramValues[i]);
        } else {
            point.setY(j);
            point.setX(histogramValues[i]);
        }

        this->appendPoint(point);
    }
}

GraphWidgetHistogram::GraphWidgetHistogram(QVector<float> histogramValues, bool graphInYDirection,
                                           double start, double interval, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    double j = start;
    for (int i = 0; i < histogramValues.count(); i++, j+=interval) {
        QPointF point;
        if (graphInYDirection) {
            point.setX(j);
            point.setY(histogramValues[i]);
        } else {
            point.setY(j);
            point.setX(histogramValues[i]);
        }

        this->appendPoint(point);
    }

}
GraphWidgetHistogram::GraphWidgetHistogram(QVector<double> histogramValues, bool graphInYDirection,
                                           double start, double interval, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    double j = start;
    for (int i = 0; i < histogramValues.count(); i++, j+=interval) {
        QPointF point;
        if (graphInYDirection) {
            point.setX(j);
            point.setY(histogramValues[i]);
        } else {
            point.setY(j);
            point.setX(histogramValues[i]);
        }

        this->appendPoint(point);
    }
}

GraphWidgetHistogram::GraphWidgetHistogram(QVector<QPointF> values, QColor color, float width, QString title) :
    GraphWidgetObject(color, width, title)
{
    foreach (QPointF point, values) {
        this->appendPoint(point);
    }
}

void GraphWidgetHistogram::draw(QPen pen)
{
    glColor4f(pen.color().redF(), pen.color().greenF(), pen.color().blueF(), pen.color().alphaF());
    glLineWidth(pen.widthF());

    for (int i = 0; i < points.count(); i++) {
        glBegin(GL_LINES);
        {
            glVertex2f(points[i].x(), 0.0f);
            glVertex2f(points[i].x(), points[i].y());
        }
        glEnd();
    }
}
